 //
//  KWLHomeViewController.m
//  KWNLaywerClient
//
//  Created by 张明磊 on 14/11/6.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "KWLHomeViewController.h"
#import "RESideMenu.h"
#import "KWNNetwork.h"
#import "Model_questionList.h"
#import "UIButton+WebCache.h"
#import "KWLWaitQuestionViewController.h"
#import "KWLMyListViewController.h"
#import "KWLQDetailViewController.h"
#import "KWLLoginViewController.h"
#import "Model_user.h"
#import "MLBlackTransition.h"
#import "KWNPhotoDetailViewController.h"
#import "MKNetworkKit.h"
#import "KWNURL.h"
//上拉加载更多
#import "MJRefresh.h"
#import "KWLAppConsole.h"

#import "KFLIsloginstuRequest.h"
#import "KWLScanCodeLoginViewController.h"

//新版访问
#import "KFLBeGoodAtQuestionRequest.h"
#import "KFLAllQuestionListRequest.h"
//新版聊天页
#import "KFWMessageViewController.h"
#import "KFWNotificationCenterViewController.h"
#import "KFLNotificationNumRequest.h"

typedef NS_ENUM(NSInteger, KWNQDetailCellTag)
{
    KWNQDetailCellTag_caina_r       = 100,
    KWNQDetailCellTag_viewBack             ,
    KWNQDetailCellTag_clickCaiNa           ,
    KWNQDetailCellTag_cainaAlter           ,
    KWNQDetailCellTag_loginOut             ,
    KWNQDetailCellTag_imageOne           ,
    KWNQDetailCellTag_imageTwo           ,
};

#undef  UnSelectTextColor
#define UnSelectTextColor RGB(189,189,189)

#undef  SelectTextColor
#define SelectTextColor RGB(91, 165, 229)

#undef  GRSelectViewFrame
#define GRSelectViewFrame CGRectMake(20, _label_geren.frame.origin.y + _label_geren.frame.size.height - 4,MainScreenWidth/2 - 40, 4)

#undef  GSSelectViewFrame
#define GSSelectViewFrame CGRectMake(_label_gongsi.frame.origin.x + 20, _label_gongsi.frame.origin.y + _label_gongsi.frame.size.height - 4, MainScreenWidth/2 - 40, 4)

typedef NS_ENUM(NSInteger, KWNFindMMButtonTag){
    KWNHomeButtonTag_back              = 0,
    KWNHomeButtonTag_receive                ,
};

@interface KWLHomeViewController ()<UITableViewDataSource,UITableViewDelegate,MWPhotoBrowserDelegate,UIAlertViewDelegate>

@property (strong, nonatomic) NSMutableArray *array_goodAtData;
@property (strong, nonatomic) NSMutableArray *array_AllData;
@property (weak, nonatomic) UIView *imageView_title;

@property (strong, nonatomic) NSMutableArray *array_photo;

@property (weak, nonatomic) UILabel *label_geren;
@property (weak, nonatomic) UILabel *label_gongsi;
@property (assign, nonatomic) NSInteger int_beforeSelect;
@property (weak,nonatomic) UITableView *tab_goodAtTab;
@property (weak,nonatomic) UITableView *tab_allTab;


@property (strong, nonatomic) NSArray *array_location;
@property (strong,nonatomic) MKNetworkEngine *home_engine;
@property NSInteger goodAtStartNum;
@property NSInteger allStartNum;

@property (weak, nonatomic) UIImageView *imageView_reload;

@property (assign, nonatomic) BOOL bool_first;
@property (assign, nonatomic) BOOL isAlreadyToken;//YES 已经弹出token不对的alert；NO 未弹出

#pragma mark - 列表刷新是否为空 -
/**
 *  列表刷新是否为空
 */
@property (assign, nonatomic) BOOL bool_empty;

/**
 下拉刷新
 **/
@property (assign, nonatomic) BOOL reloading;

/**
 下拉刷新
 **/
@property (assign, nonatomic) BOOL reloading_now;

@end

@implementation KWLHomeViewController

#pragma mark - 退登 -
/**
 *  退登
 */
- (void)didClickLoginOut{
    KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
    [self pushViewController:login];
}

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _goodAtStartNum = 0;
    _allStartNum = 0;
    
// AS 快法务 KLW 2014-12-29
    _isAlreadyToken = NO;
// AE 快法务 KLW 2014-12-29
    
    _array_goodAtData = [[NSMutableArray alloc] init];
    _array_AllData = [[NSMutableArray alloc] init];
    _home_engine = [[MKNetworkEngine alloc] init];
    
    _bool_first = YES;
    
    NSMutableArray *array_data = [NSMutableArray array];
    _array_photo  = array_data;
    
    _array_location =@[
                       @"北京",@"上海",@"天津",@"重庆",@"黑龙江省",@"吉林省",@"辽宁省",@"河北省",@"山西省",@"内蒙古",@"山东省",@"安徽省",@"江苏省",@"浙江省",@"江西省",@"福建省",@"河南省",@"湖北省",@"湖南省",@"广东省",@"广西",@"海南省",@"四川省",@"贵州省",@"云南省",@"西藏",@"陕西省",@"甘肃省",@"青海省",@"宁夏",@"新疆",@"香港",@"澳门",@"台湾省"];
    
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        NSArray *array_tmp = @[
//                               @"北京",@"上海",@"天津",@"重庆",@"黑龙江省",@"吉林省",@"辽宁省",@"河北省",@"山西省",@"内蒙古",@"山东省",@"安徽省",@"江苏省",@"浙江省",@"江西省",@"福建省",@"河南省",@"湖北省",@"湖南省",@"广东省",@"广西",@"海南省",@"四川省",@"贵州省",@"云南省",@"西藏",@"陕西省",@"甘肃省",@"青海省",@"宁夏",@"新疆",@"香港",@"澳门",@"台湾省"];
//        dispatch_async(dispatch_get_main_queue(), ^{
//            _array_location = array_tmp;
//        });
//    });
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didClickLoginOut) name:Notification_KWNLoginOut object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadHomeViewData) name:@"notificaition_KWLReloadHome" object:nil];
    
    //登录并验证网页在线
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadHomeAndIsWebLog) name:@"notificaition_KWLReloadHomeAndIsWebLog" object:nil];

    [self UI_homeTitle];
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:Notification_KWNLoginOut object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"notificaition_KWLreloadHome" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"notificaition_KWLReloadHomeAndIsWebLog" object:nil];
    _array_location = nil;
    _imageView_title = nil;
    _label_geren = nil;
    _label_gongsi = nil;
    _home_engine = nil;
    _tab_allTab = nil;
    _tab_goodAtTab = nil;
    _array_goodAtData = nil;
    _array_AllData = nil;
    _array_photo = nil;
}


- (void)viewDidAppear:(BOOL)animated{
//    [KWLAppConsole sharedInstance].viewController = self;
    [super viewDidAppear:animated];
    if(_bool_first){
        [self UI_homeBody];

        if(!_tab_allTab.hidden && _tab_allTab){
            _allStartNum = 0;
            [self getAllQuestionListData];
        }
        else{
            _goodAtStartNum = 0;
            [self getGoodAtQuestionListData];
        }
        _bool_first = NO;
    }
    [self getUnReadCount];
}


#pragma mark - 新访问数据——擅长
- (void)getGoodAtQuestionListData
{
    [SVProgressHUD showWithStatus:@"加载中..." maskType:SVProgressHUDMaskTypeClear];
    
    KFLBeGoodAtQuestionRequest *request = [[KFLBeGoodAtQuestionRequest alloc] initRequest];
    request.goodAtQuestion_startNum = [NSString stringWithFormat:@"%ld",(long)_goodAtStartNum];
    request.goodAtQuestion_displaynum = [NSString stringWithFormat:@"%d",kCountOfPage];
    __weak KWLHomeViewController *aself = self;

    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        [aself.tab_goodAtTab headerEndRefreshing];
        [aself.tab_goodAtTab footerEndRefreshing];

        if(aself.imageView_reload){
            [aself.imageView_reload.layer removeAllAnimations];
        }

        switch (stateCode) {
            case 10000:
            {
                [SVProgressHUD dismiss];

                if (aself.goodAtStartNum == 0) {
                    [aself.array_goodAtData removeAllObjects];
                }
                aself.goodAtStartNum = aself.goodAtStartNum + kCountOfPage;
                [aself.array_goodAtData addObjectsFromArray:result];
                if (aself.array_goodAtData.count == 0) {
                    aself.bool_empty = YES;
                }
                else
                {
                    aself.bool_empty = NO;
                }
                aself.tab_goodAtTab.hidden = NO;
                aself.tab_allTab.hidden = YES;
                [aself.tab_goodAtTab reloadData];
                //引导
                if ([Model_user sharedInstance].bool_isFirst){
                    [[RESideMenu sharedInstance] setPanGestureEnabled:NO];
                    UIView *view_d = [[UIView alloc] initWithFrame:self.view.frame];
                    [self.view addSubview:view_d];
                    view_d.tag = 300;
                    UIImageView *imageView_one = [[UIImageView alloc] initWithFrame:self.view.frame];
                    imageView_one.contentMode = UIViewContentModeTop;
                    imageView_one.image = [UIImage imageFileName:@"yindao_one.png"];
                    [view_d addSubview:imageView_one];
                    
                    UIButton *button_one = [UIButton buttonWithType:UIButtonTypeCustom];
                    button_one.frame = CGRectMake(102, Iphone5_size(448, 360), 116, 40);
                    [button_one setImage:[UIImage imageFileName:@"begin_button_one.png"] forState:UIControlStateNormal];
                    [button_one setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [button_one addTarget:self action:@selector(didClickButton_one:)forControlEvents:UIControlEventTouchUpInside];
                    [self.view addSubview:button_one];
                    [Model_user sharedInstance].bool_isFirst = NO;
                }
            }
                break;
            case 10003:
            {
                [SVProgressHUD dismiss];

                [aself tokenIsFailure];

            }
                break;
            case 10009:
            {
                NSString *msg = [result objectAtIndex:0];

                if (aself.array_goodAtData.count == 0) {
                    aself.bool_empty = YES;
                    [SVProgressHUD dismissWithSuccess:@"没有数据" afterDelay:1.5];
                }
                else
                {
                    [SVProgressHUD dismissWithSuccess:msg afterDelay:1.5];
                    aself.bool_empty = NO;
                }
                
                aself.tab_goodAtTab.hidden = NO;
                aself.tab_allTab.hidden = YES;
            }
                break;

            default:
            {
                NSString *msg = [result objectAtIndex:0];
                [SVProgressHUD dismissWithError:msg afterDelay:1.5];

                if (aself.array_goodAtData.count == 0) {
                    aself.bool_empty = YES;
                }
                else
                {
                    aself.bool_empty = NO;
                }
                aself.tab_goodAtTab.hidden = NO;
                aself.tab_allTab.hidden = YES;

                if ([Model_user sharedInstance].bool_isFirst){
                    [[RESideMenu sharedInstance] setPanGestureEnabled:NO];
                    
                    UIView *view_d = [[UIView alloc] initWithFrame:self.view.frame];
                    [self.view addSubview:view_d];
                    view_d.tag = 300;
                    UIImageView *imageView_one = [[UIImageView alloc] initWithFrame:self.view.frame];
                    imageView_one.contentMode = UIViewContentModeTop;
                    imageView_one.image = [UIImage imageFileName:@"yindao_one.png"];
                    [view_d addSubview:imageView_one];
                    
                    UIButton *button_one = [UIButton buttonWithType:UIButtonTypeCustom];
                    button_one.frame = CGRectMake(102, Iphone5_size(448, 360), 116, 40);
                    [button_one setImage:[UIImage imageFileName:@"begin_button_one.png"] forState:UIControlStateNormal];
                    [button_one setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [button_one addTarget:self action:@selector(didClickButton_one:)forControlEvents:UIControlEventTouchUpInside];
                    [self.view addSubview:button_one];
                    [Model_user sharedInstance].bool_isFirst = NO;
                }
            }
                break;
        }
        
    }];
}

- (void)getAllQuestionListData
{
    [SVProgressHUD showWithStatus:@"加载中..." maskType:SVProgressHUDMaskTypeClear];
    
    KFLAllQuestionListRequest *request = [[KFLAllQuestionListRequest alloc] initRequest];
    request.allQuestion_startNum = [NSString stringWithFormat:@"%ld",(long)_allStartNum];
    request.allQuestion_displaynum = [NSString stringWithFormat:@"%d",kCountOfPage];
    
    __weak KWLHomeViewController *aself = self;
    
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        
        [aself.tab_allTab headerEndRefreshing];
        [aself.tab_allTab footerEndRefreshing];

        if(aself.imageView_reload){
            [aself.imageView_reload.layer removeAllAnimations];
        }

        switch (stateCode) {
            case 10000:
            {
                [SVProgressHUD dismiss];

                if (aself.allStartNum == 0) {
                    [aself.array_AllData removeAllObjects];
                }
                aself.allStartNum = aself.allStartNum + kCountOfPage;
                [aself.array_AllData addObjectsFromArray:result];
                if (aself.array_AllData.count == 0) {
                    aself.bool_empty = YES;
                }
                else
                {
                    aself.bool_empty = NO;
                }
                aself.tab_goodAtTab.hidden = YES;
                aself.tab_allTab.hidden = NO;
                [aself.tab_allTab reloadData];

            }
                break;
            case 10003:
            {
                [SVProgressHUD dismiss];
                [aself tokenIsFailure];
            }
                break;
            case 10009:
            {
                NSString *msg = [result objectAtIndex:0];

                if (aself.array_AllData.count == 0) {
                    aself.bool_empty = YES;
                    [SVProgressHUD dismissWithSuccess:@"没有数据" afterDelay:1.5];
                }
                else
                {
                    aself.bool_empty = NO;
                    [SVProgressHUD dismissWithSuccess:msg afterDelay:1.5];
                }
                aself.tab_goodAtTab.hidden = YES;
                aself.tab_allTab.hidden = NO;
            }
                break;

            default:
            {
                NSString *msg = [result objectAtIndex:0];
                [SVProgressHUD dismissWithError:msg afterDelay:1.5];

                if (aself.array_AllData.count == 0) {
                    aself.bool_empty = YES;
                }
                else
                {
                    aself.bool_empty = NO;
                }
                
                aself.tab_goodAtTab.hidden = YES;
                aself.tab_allTab.hidden = NO;
            }
                break;
        }
        
    }];
}

#pragma mark - 更新未读数量 -
/**
 *  更新未读数量
 */
- (void)updateUnread:(NSInteger)num
{
    UIButton *button_receive = (UIButton *)[self.view viewWithTag:KWNHomeButtonTag_receive];
    UIButton *button_unread = (UIButton *)[button_receive viewWithTag:TagOfView + 1];
    if (num > 0) {
        
        if (button_unread) {
            button_unread.hidden = NO;
        }
        else
        {
            button_unread = [UIButton buttonWithType:UIButtonTypeCustom];
            button_unread.frame = CGRectMake(32, 10, 6, 6);
            button_unread.backgroundColor = [UIColor redColor];
            button_unread.layer.cornerRadius = 3;
            button_unread.hidden = NO;
            button_unread.tag = TagOfView + 1;
//            button_unread.titleLabel.font = [UIFont systemFontOfSize:11];
//            [button_unread setTitleEdgeInsets:UIEdgeInsetsMake(0, 1, 0, 0)];
            [button_receive addSubview:button_unread];
        }
//        if (num > 9) {
//            [button_unread setTitle:[NSString stringWithFormat:@"N"] forState:UIControlStateNormal];
//        }
//        else
//        {
//            [button_unread setTitle:[NSString stringWithFormat:@"%li",(long)num] forState:UIControlStateNormal];
//        }
    }
    else
    {
        if (button_unread) {
            button_unread.hidden = YES;
        }
    }
}

//[UIUtils view_showProgressHUD:@"加载中..." inView:self.view withType:0];
//[UIUtils view_hideProgressHUDinView:self.view];

- (void)didClickButton_one:(UIButton *)button{
    [button removeFromSuperview];
    UIView *imageViewTwo = (UIView *)[self.view viewWithTag:300];
    [imageViewTwo removeFromSuperview];
    
    UIView *view_d = [[UIView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:view_d];
    view_d.tag = 301;
    
    UIImageView *imageView_two = [[UIImageView alloc] initWithFrame:self.view.frame];
    imageView_two.contentMode = UIViewContentModeTop;
    imageView_two.image = [UIImage imageFileName:@"yindao_two.png"];
    [view_d addSubview:imageView_two];
    
    UIButton *button_two = [UIButton buttonWithType:UIButtonTypeCustom];
    button_two.frame = CGRectMake(102, Iphone5_size(448, 360), 116, 40);
    [button_two setImage:[UIImage imageFileName:@"begin_button_two.png"] forState:UIControlStateNormal];
    [button_two setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button_two addTarget:self action:@selector(didClickButton_two:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_two];
}

#pragma mark - 移除指导页 -
/**
 *  移除指导页
 */
- (void)didClickButton_two:(UIButton *)button{
    [button removeFromSuperview];
    UIView *imageViewTwo = (UIView *)[self.view viewWithTag:301];
    [imageViewTwo removeFromSuperview];
    
    [[RESideMenu sharedInstance] setPanGestureEnabled:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"HomePage"];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"HomePage"];
    [_home_engine cancelAllOperations];
}

- (void)UI_homeTitle{
//    self.view.backgroundColor = RGB(239,239,244);
    
    UIView *imageView_title = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44 + IOS7_SIZE)];
    imageView_title.backgroundColor = RGB(91, 165, 229);
    [self.view addSubview:imageView_title];
    _imageView_title = imageView_title;
    
    UIButton *button_menu = [UIButton buttonWithType:UIButtonTypeCustom];
    button_menu.frame = CGRectMake(0, IOS7_SIZE, 60, 45);
    [button_menu setImage:[UIImage imageFileName:@"btn_leftList.png"] forState:UIControlStateNormal];
    button_menu.tag = KWNHomeButtonTag_back;
    [button_menu addTarget:self action:@selector(didClickButton_home:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_menu];
    
    UIButton *button_receive = [UIButton buttonWithType:UIButtonTypeCustom];
    button_receive.frame = CGRectMake(imageView_title.frame.size.width - 50, button_menu.frame.origin.y, 60, 45);
    button_receive.backgroundColor = [UIColor clearColor];
    [button_receive setImage:[UIImage imageFileName:@"btn_myQuestion.png"] forState:UIControlStateNormal];
    button_receive.tag = KWNHomeButtonTag_receive;
    [button_receive addTarget:self action:@selector(didClickButton_home:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_receive];
    
    UIImageView *imageView_logo = [[UIImageView alloc] initWithFrame:CGRectMake(90, IOS7_SIZE + 12, 140, 19)];
    imageView_logo.image = [UIImage imageFileName:@"home_lawyer_title.png"];
    [self.view addSubview:imageView_logo];

    UILabel *label_geren = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView_title.frame.origin.y + imageView_title.frame.size.height, MainScreenWidth/2, 44)];
    label_geren.userInteractionEnabled = YES;
    label_geren.text = @"擅长的领域";
    label_geren.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    label_geren.textColor = SelectTextColor;
    label_geren.textAlignment = NSTextAlignmentCenter;
    label_geren.backgroundColor = [UIColor whiteColor];
    label_geren.tag = 100;
    CALayer *layer_geren = [[CALayer alloc] init];
    layer_geren.borderColor = UnSelectTextColor.CGColor;
    layer_geren.borderWidth = 0.5;
    layer_geren.frame = CGRectMake(0, label_geren.frame.size.height, label_geren.frame.size.width, 0.5);
    [label_geren.layer addSublayer:layer_geren];
    
//    CALayer *layer_geren_fenge = [[CALayer alloc] init];
//    layer_geren_fenge.borderColor = UnSelectTextColor.CGColor;
//    layer_geren_fenge.borderWidth = 0.5;
//    layer_geren_fenge.frame = CGRectMake(label_geren.frame.size.width, 10, 0.5, 24);
//    [label_geren.layer addSublayer:layer_geren_fenge];
    
    UITapGestureRecognizer *gerenTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap:)];
    [label_geren addGestureRecognizer:gerenTap];
    [self.view addSubview:label_geren];
    _label_geren = label_geren;
    
    UILabel *label_gongsi = [[UILabel alloc] initWithFrame:CGRectMake(label_geren.frame.size.width + label_geren.frame.origin.x, imageView_title.frame.origin.y + imageView_title.frame.size.height, MainScreenWidth/2, 44)];
    label_gongsi.text = @"其他领域";
    label_gongsi.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    label_gongsi.userInteractionEnabled = YES;
    label_gongsi.textColor = UnSelectTextColor;
    label_gongsi.textAlignment = NSTextAlignmentCenter;
    label_gongsi.backgroundColor = [UIColor whiteColor];
    label_gongsi.tag = 101;
    CALayer *layer_gongsi = [[CALayer alloc] init];
    layer_gongsi.borderColor = UnSelectTextColor.CGColor;
    layer_gongsi.borderWidth = 0.5;
    layer_gongsi.frame = CGRectMake(0, label_gongsi.frame.size.height, label_gongsi.frame.size.width, 0.5);
    [label_gongsi.layer addSublayer:layer_gongsi];
    UITapGestureRecognizer *gongsiTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap:)];
    [label_gongsi addGestureRecognizer:gongsiTap];
    [self.view addSubview:label_gongsi];
    _label_gongsi = label_gongsi;
    
    UIView *view_line = [[UIView alloc] initWithFrame:CGRectMake(20, label_geren.frame.origin.y + label_geren.frame.size.height - 4, MainScreenWidth/2 - 40, 4)];
    view_line.backgroundColor = RGB(91, 165, 229);
    view_line.tag = 102;
    [self.view addSubview:view_line];
    
    UIView *view_zhongjian = [[UIView alloc] initWithFrame:CGRectMake(159, label_geren.frame.origin.y + 10, 1, 25)];
    view_zhongjian.backgroundColor = RGB(220, 220, 220);
    [self.view addSubview:view_zhongjian];
    
    UIView *view_dibu = [[UIView alloc] initWithFrame:CGRectMake(0, view_line.frame.origin.y + view_line.frame.size.height, 320, 1)];
    view_dibu.backgroundColor = RGB(220, 220, 220);
    [self.view addSubview:view_dibu];
    
    UIButton *button_reload = [UIButton buttonWithType:UIButtonTypeCustom];
    button_reload.frame = CGRectMake(250, self.view.frame.size.height - 75, 55, 55);
    button_reload.backgroundColor = [UIColor clearColor];
    [button_reload setImage:[UIImage imageFileName:@"button_reload.png"] forState:UIControlStateNormal];
    [button_reload addTarget:self action:@selector(didClickButton_reload:)forControlEvents:UIControlEventTouchUpInside];
    [self.view insertSubview:button_reload atIndex:2];
    
    UIImageView *imageView_animetion = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 38, 38)];
    imageView_animetion.image = [UIImage imageFileName:@"animetion_reload.png"];
    [button_reload addSubview:imageView_animetion];
    _imageView_reload = imageView_animetion;
}

- (void)UI_homeBody{
    if(!_tab_goodAtTab){
        UITableView *tableView_home = [[UITableView alloc] initWithFrame:CGRectMake(_imageView_title.frame.origin.x, _imageView_title.frame.origin.y + _imageView_title.frame.size.height + 45, _imageView_title.frame.size.width, self.view.frame.size.height - _imageView_title.frame.size.height - 45)];
        tableView_home.backgroundColor = [UIColor clearColor];
        tableView_home.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView_home.delegate = self;
        tableView_home.dataSource = self;
        tableView_home.tag = 200;
        [self.view insertSubview:tableView_home atIndex:0];
        
        __weak KWLHomeViewController *aself = (KWLHomeViewController *)self;
        
        //加入下拉加载更多
        [tableView_home addHeaderWithCallback:^{
            aself.goodAtStartNum = 0;
            [aself getGoodAtQuestionListData];
        }];
        //加入上拉加载更多
        [tableView_home addFooterWithCallback:^{
            [aself getGoodAtQuestionListData];
        }];
        _tab_goodAtTab = tableView_home;
        _tab_goodAtTab.hidden = NO;
        
        UITableView *tableView_home_other = [[UITableView alloc] initWithFrame:CGRectMake(_imageView_title.frame.origin.x, _imageView_title.frame.origin.y + _imageView_title.frame.size.height + 45, _imageView_title.frame.size.width, self.view.frame.size.height - _imageView_title.frame.size.height - 45)];
//        tableView_home_other.backgroundColor = RGB(239,239,244);
        tableView_home_other.backgroundColor = [UIColor clearColor];
        tableView_home_other.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView_home_other.delegate = self;
        tableView_home_other.dataSource = self;
        tableView_home_other.tag = 201;
        [self.view insertSubview:tableView_home_other atIndex:1];
        //下拉刷新
        [tableView_home_other addHeaderWithCallback:^{
            aself.allStartNum = 0;
            [aself getAllQuestionListData];
        }];
        
        //加入上拉加在更多
        [tableView_home_other addFooterWithCallback:^{
            [aself getAllQuestionListData];
        }];
        _tab_allTab = tableView_home_other;
        _tab_allTab.hidden = YES;
    }
    else{
        if(_tab_allTab){
            if(_tab_allTab.hidden){
                [_tab_goodAtTab reloadData];
            }
            else{
                [_tab_allTab reloadData];
            }
        }
        else{
            [_tab_goodAtTab reloadData];
        }
    }
}

///刷新Home页面
- (void)reloadHomeViewData{
    if(_tab_goodAtTab.hidden == NO)
    {
        _goodAtStartNum = 0;
        [self getGoodAtQuestionListData];
    }
    else
    {
        _allStartNum = 0;
        [self getAllQuestionListData];
    }
}

- (void)reloadHomeAndIsWebLog
{
    [self isLoginstu:1];
}

- (void)labelTap:(UIGestureRecognizer *)tap{
    UILabel *lab = (UILabel *)tap.view;
    switch (lab.tag){
        case 100:
        {
            if (![lab.textColor isEqual:SelectTextColor])
            {
                _goodAtStartNum = 0;
                [self getGoodAtQuestionListData];
                
                _int_beforeSelect = lab.tag;
                UIView *aview = [self.view viewWithTag:102];
                [UIView animateWithDuration:0.2 animations:^{
                    _label_geren.textColor = SelectTextColor;
                    _label_gongsi.textColor = UnSelectTextColor;
                    aview.frame = GRSelectViewFrame;
                }];
            }
        }break;
        case 101:
        {
            if (![lab.textColor isEqual:SelectTextColor])
            {
                _allStartNum = 0;
                [self getAllQuestionListData];
                _int_beforeSelect = lab.tag;
                
                UIView *aview = [self.view viewWithTag:102];
                [UIView animateWithDuration:0.2 animations:^{
                    _label_geren.textColor = UnSelectTextColor;
                    _label_gongsi.textColor = SelectTextColor;
                    aview.frame = GSSelectViewFrame;
                }];
            }
        }break;
        default:
            break;
    }
}

// CE 快法务 KLW 2015-01-15
#pragma mark - 点击界面按钮 -
/**
 *  点击界面按钮
 */
- (void)didClickButton_home:(UIButton *)button{
    switch (button.tag) {
        case KWNHomeButtonTag_back:{
            [[RESideMenu sharedInstance] presentMenuViewController];
            [MobClick event:@"caidan"];
        }break;
        case KWNHomeButtonTag_receive:{
            KFWNotificationCenterViewController *controller_my = [[KFWNotificationCenterViewController alloc] init];
            [self pushViewController:controller_my];
//            [MobClick event:@"caidanweiti"];
        }break;
        default:
            break;
    }
}

#pragma mark - 验证网页是否登录 -
- (void)isLoginstu:(NSInteger)state
{
    [SVProgressHUD showWithStatus:@"加载中..." maskType:SVProgressHUDMaskTypeClear];
    KFLIsloginstuRequest *isLoginstuRequest = [[KFLIsloginstuRequest alloc] initRequest];
    [isLoginstuRequest startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        [SVProgressHUD dismiss];
        switch (stateCode) {
            case 10000:
            {
                if (state == 1) {
                    [self reloadHomeViewData];
                }

                KWLScanCodeLoginViewController *scanCodeLogVC = [[KWLScanCodeLoginViewController alloc]initWithCodeStr:nil];
                [self pushViewController:scanCodeLogVC];
                [scanCodeLogVC webLoginSucceed];
            }
                break;
            case 10003:
            {
                [self tokenIsFailure];
            }
                break;
            case 10011:
            {
                if (state == 1) {
                    [self reloadHomeViewData];
                }
            }
                break;
            default:
            {
                NSString *string_msg  = result[0];
                [SVProgressHUD showErrorWithStatus:string_msg duration:1.5];
            }
                break;
        }
    }];
}

#pragma mark - 按钮刷新列表 -
/**
 *  按钮刷新列表
 */
- (void)didClickButton_reload:(UIButton *)button{
    CAAnimation *nimation = [_imageView_reload.layer animationForKey:@"zml"];
    if(nimation){
        [_imageView_reload.layer animationDidStart:nimation];
    }
    else{
        CABasicAnimation *animation = [[CABasicAnimation animationWithKeyPath:@"transform"] copy];
        animation.delegate = self;
        animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2 , 0, 0, 1.0)];
        animation.duration = 0.3;
        animation.cumulative = YES;
        animation.repeatCount = 1000;
        //animation.
        [_imageView_reload.layer addAnimation:animation forKey:@"zml"];
        //[_imageView_reload.layer animationDidStart:aAnimation];
    }
    [self reloadHomeViewData];
}

#pragma mark - UITableViewDelegate -

/**
 *  列表数据源
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(_bool_empty){
        return 1;
    }
    else{
        if(tableView == _tab_goodAtTab){
            return _array_goodAtData.count;
        }
        else{
            return _array_AllData.count;
        }
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(!_bool_empty){
        static NSString *CellIdentifier = @"Cell_questionList";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
            
            UIImageView *imageviw_wen = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
            imageviw_wen.image = [UIImage imageFileName:@"wen.png"];
            
            UIImageView *imageview_ren = [[UIImageView alloc] initWithFrame:CGRectMake(imageviw_wen.frame.origin.x + imageviw_wen.frame.size.width + 3, 13, 11, 15)];
            imageview_ren.image = [UIImage imageFileName:@"image_free_Person.png"];
            
            UILabel *label_name = [UIUtils creatLabel];
            label_name.frame = CGRectMake(imageview_ren.frame.origin.x + imageview_ren.frame.size.width + 3, 13, 80, 15);
            label_name.font = FontOfHelveticaBold(13);
            label_name.textColor = RGB(206, 206, 206);
            label_name.tag = TagOfView + 1;
            
            UIImageView *imageview_message = [[UIImageView alloc] initWithFrame:CGRectMake(MainScreenWidth - 143, 10, 20, 19)];
            imageview_message.image = [UIImage imageFileName:@"image_qListType.png"];
            
            UILabel *label_QuestionType = [UIUtils creatLabel];
            label_QuestionType.frame = CGRectMake(MainScreenWidth - 120, 13, 52, 15);
            label_QuestionType.textColor = RGB(134, 177, 217);
            label_QuestionType.font = FontOfHelveticaBold(13);;
            label_QuestionType.tag = TagOfView + 2;

            UILabel *label_QuestionDetailType = [UIUtils creatLabel];
            label_QuestionDetailType.frame = CGRectMake(MainScreenWidth - 62, 13, 52, 15);
            label_QuestionDetailType.textColor = RGB(134, 177, 217);
            label_QuestionDetailType.font = FontOfHelveticaBold(13);
            label_QuestionDetailType.tag = TagOfView + 3;

            UILabel *label_text = [UIUtils creatLabel];
            [label_text sizeToFit];
            label_text.numberOfLines = 0;
            label_text.font = FontOfQuestionList;
            label_text.frame = CGRectMake(10, 40, MainScreenWidth - 20, 16);
            label_text.textColor = ColorOfQuestionList;
            label_text.tag = TagOfView + 4;
            
            UIButton *button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
            button_photo.frame = CGRectMake(0, 0, 0, 0);
            button_photo.backgroundColor = [UIColor blackColor];
            [button_photo addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
            [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
            button_photo.tag = KWNQDetailCellTag_imageOne;
            button_photo.hidden = YES;
            
            UIButton *button_addPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
            button_addPhoto.backgroundColor = [UIColor blackColor];
            button_addPhoto.frame = CGRectMake(0, 0, 0, 0);
            [button_addPhoto addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
            [button_addPhoto.imageView setContentMode:UIViewContentModeScaleAspectFit];
            button_addPhoto.tag = KWNQDetailCellTag_imageTwo;
            button_addPhoto.hidden = YES;

            UILabel *label_time = [UIUtils creatLabel];
            label_time.font = FontOfSystem(13);
            label_time.frame = CGRectZero;
            label_time.textColor = RGB(194, 194, 194);
            label_time.tag = TagOfView + 5;

            UIImageView *imageview_line = [[UIImageView alloc] initWithFrame:CGRectZero];
            imageview_line.tag = TagOfView + 6;
            
            [cell addSubview:imageviw_wen];
            [cell addSubview:imageview_ren];
            [cell addSubview:imageview_message];
            [cell addSubview:label_QuestionType];
            [cell addSubview:label_name];
            [cell addSubview:label_QuestionDetailType];
            [cell addSubview:label_text];
            [cell addSubview:button_addPhoto];
            [cell addSubview:button_photo];
            [cell addSubview:label_time];
            [cell addSubview:imageview_line];

        }
        
        UILabel *label_name_ = (UILabel *)[cell viewWithTag:TagOfView + 1];
        UILabel *label_QuestionType_ = (UILabel *)[cell viewWithTag:TagOfView + 2];
        UILabel *label_QuestionDetailType_ = (UILabel *)[cell viewWithTag:TagOfView + 3];
        UILabel *label_text_ = (UILabel *)[cell viewWithTag:TagOfView + 4];
        UILabel *label_time_ = (UILabel *)[cell viewWithTag:TagOfView + 5];
        UIButton *button_photo_ = (UIButton *)[cell viewWithTag:KWNQDetailCellTag_imageOne];
        UIButton *button_addPhoto_ = (UIButton *)[cell viewWithTag:KWNQDetailCellTag_imageTwo];
        UIImageView *imageview_line_ = (UIImageView *)[cell viewWithTag:TagOfView + 6];
        
        Model_questionList *model_list = nil;
        if (tableView == _tab_goodAtTab) {
            model_list = _array_goodAtData[indexPath.row];
        }
        else
        {
            model_list = _array_AllData[indexPath.row];
        }
        
        NSInteger kind_area = model_list.string_area.integerValue;
        label_name_.text = [NSString stringWithFormat:@"%@网友",_array_location[kind_area]];
        
        NSInteger kind = model_list.string_kind.integerValue;
        NSArray *arr = [UIUtils getQuestionTypeWithkind:kind];
        label_QuestionType_.text = arr[0];
        label_QuestionDetailType_.text = arr[1];
        
        label_text_.text = model_list.string_content;
        CGFloat height = [UIUtils heightFor:label_text_.text withFont:FontOfQuestionList labWidth:MainScreenWidth-20];
        
        if (height >= 40) {
            height = 40;
        }
        else
        {
            height = 20;
        }
        
        label_text_.frame = CGRectMake(10, 40, MainScreenWidth - 20, height);
        
        label_time_.text = model_list.string_time;
        
        
        if (model_list.array_img_small.count > 0) {
            
            button_photo_.frame = CGRectMake(10, label_text_.frame.origin.y + label_text_.frame.size.height + 10, 50, 50);
            [button_photo_ sd_setBackgroundImageWithURL:[NSURL URLWithString:model_list.array_img_small[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            button_photo_.hidden = NO;
            
            if (model_list.array_img_small.count > 1) {
                button_addPhoto_.frame = CGRectMake(button_photo_.frame.origin.x + button_photo_.frame.size.width, label_text_.frame.origin.y + label_text_.frame.size.height + 10, 50, 50);
                [button_addPhoto_ sd_setBackgroundImageWithURL:[NSURL URLWithString:model_list.array_img_small[1]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
                button_addPhoto_.hidden = NO;

            }
            label_time_.frame = CGRectMake(10, button_photo_.frame.origin.y + button_photo_.frame.size.height + 10, 200, 15);
        }
        else
        {
            button_photo_.hidden = YES;
            button_addPhoto_.hidden = YES;
            label_time_.frame = CGRectMake(10, label_text_.frame.origin.y + label_text_.frame.size.height + 10, 200, 15);
        }
        
        imageview_line_.frame = CGRectMake(0, label_time_.frame.origin.y + label_time_.frame.size.height + 9, MainScreenWidth, 0.5);
        imageview_line_.backgroundColor = RGB(220, 220, 220);
        
        return cell;
    }
    else
    {
        static NSString *CellIdentifier = @"Cell_questionListEmpty";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil){
            cell = [[UITableViewCell alloc] init];
            //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        UIImageView *imageView_noData = [[UIImageView alloc] initWithFrame:CGRectMake((tableView.frame.size.width - 164)/2, (tableView.frame.size.height - 234)/2, 164, 234)];

//        UIImageView *imageView_noData = [[UIImageView alloc] initWithFrame:CGRectMake(78, 80, 164, 234)];
        imageView_noData.image = [UIImage imageFileName:@"noDataList.png"];
        [cell addSubview:imageView_noData];
        
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(_bool_empty){
        return tableView.frame.size.height;
    }
    else{
        
        Model_questionList *model_list = nil;
        if (tableView == _tab_goodAtTab) {
            model_list = _array_goodAtData[indexPath.row];
        }
        else
        {
            model_list = _array_AllData[indexPath.row];
        }
        
        return model_list.cgfloat_height;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (tableView == _tab_goodAtTab) {
        if (_array_goodAtData.count > 0) {
            
            Model_questionList *question = _array_goodAtData[indexPath.row];
            if (question) {
                KFWMessageViewController *controller = [[KFWMessageViewController alloc] initWithQID:question.string_id andUpdataUnread:NO];
                [self pushViewController:controller];
            }
        }
    }
    else
    {
        if (_array_AllData.count > 0) {
            
            Model_questionList *question = _array_AllData[indexPath.row];
            if (question) {
                KFWMessageViewController *controller = [[KFWMessageViewController alloc] initWithQID:question.string_id andUpdataUnread:NO];
                [self pushViewController:controller];
            }
        }
    }
}

#pragma mark - 获取未读数 -
// CS 快法务 KLW 2015-01-27
//- (void)getUnReadCount{
//    //获取未读小红点
//    NSString *string_uid = [[Model_user sharedInstance] getUserID];
//    NSString *string_token = [[Model_user sharedInstance] getToken];
//    NSMutableArray *array_sort;
//    KWNNetwork *mynet = [KWNNetwork sharedInstance];
//    array_sort = [NSMutableArray arrayWithObjects:@"lawygetunread",string_uid,string_token,Model,Version,nil];
//    NSString *string_sign = [mynet getSignWithArray:array_sort];
//    NSString *string_url = [KWNBaseURL stringByAppendingString:[NSString stringWithFormat:@"method=lawygetunread&id=%@&token=%@&src=%@&edition=%@&sig=%@",string_uid,string_token,Model,Version,string_sign]];
//    MKNetworkOperation *op = [_home_engine operationWithURLString:string_url];
//    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
//        NSError *error;
//        NSDictionary *kindDic = [NSJSONSerialization JSONObjectWithData:completedOperation.responseData options:NSJSONReadingMutableLeaves error:&error];
//        NSNumber *number_code = [kindDic objectForKey:@"code"];
//        if ([number_code intValue] == 10000) {
//            
//            NSInteger unread = 0;
//            if(![kindDic objectForKey:@"unread"] || [[kindDic objectForKey:@"unread"] isKindOfClass:[NSNull class]]){
//                unread = 0;
//            }
//            else{
//                unread = [[kindDic objectForKey:@"unread"] intValue];
//            }
//            [[Model_user sharedInstance] setUnReadCount:[NSString stringWithFormat:@"%ld",(long)unread]];
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"updateUnReadCount" object:nil];
//            [self updateUnread:unread];
//        }
//    }errorHandler:^(MKNetworkOperation *completedOperation,NSError *error) {
//        
//    }];
//    [_home_engine enqueueOperation:op];
//}
//
- (void)getUnReadCount{
    //获取未读小红点
    
    KFLNotificationNumRequest *request = [[KFLNotificationNumRequest alloc] initRequest];
    [request startToRequestWithBlock:^(NSInteger stateCode, NSMutableArray *result) {
        switch (stateCode) {
            case 10000:
            {
                NSInteger unread = 0;
                unread = [[result objectAtIndex:1] integerValue];
                [[Model_user sharedInstance] setUnReadCount:[NSString stringWithFormat:@"%ld",(long)unread]];
                [self updateUnread:unread];
            }
                break;
            default:
                break;
        }
    }];
    
    
//    MKNetworkOperation *op = [_home_engine operationWithURLString:string_url];
//    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
//        NSError *error;
//        NSDictionary *kindDic = [NSJSONSerialization JSONObjectWithData:completedOperation.responseData options:NSJSONReadingMutableLeaves error:&error];
//        NSNumber *number_code = [kindDic objectForKey:@"code"];
//        if ([number_code intValue] == 10000) {
//            
//            NSInteger unread = 0;
//            if(![kindDic objectForKey:@"unread"] || [[kindDic objectForKey:@"unread"] isKindOfClass:[NSNull class]]){
//                unread = 0;
//            }
//            else{
//                unread = [[kindDic objectForKey:@"unread"] intValue];
//            }
//            [[Model_user sharedInstance] setUnReadCount:[NSString stringWithFormat:@"%ld",(long)unread]];
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"updateUnReadCount" object:nil];
//            [self updateUnread:unread];
//        }
//    }errorHandler:^(MKNetworkOperation *completedOperation,NSError *error) {
//        
//    }];
//    [_home_engine enqueueOperation:op];
}

// CE 快法务 KLW 2015-01-27
- (void)didClickButton_addPhoto:(UIButton *)button{
    switch (button.tag) {
        case KWNQDetailCellTag_imageOne:{
            UITableViewCell *cell = [self reciveSuperViewCellWithView:button];
            UITableView *tableView = [self reciveSuperViewTableWithView:cell];
            NSIndexPath *index = [tableView indexPathForCell:cell];
            if(tableView.tag == 200){
                Model_questionList *model_list = _array_goodAtData[index.row];
                [_array_photo removeAllObjects];
                [_array_photo addObject:[model_list.array_img objectAtIndex:0]];
                if (model_list.array_img.count == 2) {
                    [_array_photo addObject:[model_list.array_img objectAtIndex:1]];
                }
            }
            else{
                Model_questionList *model_list = _array_AllData[index.row];
                [_array_photo removeAllObjects];
                [_array_photo addObject:[model_list.array_img objectAtIndex:0]];
                if (model_list.array_img.count == 2) {
                    [_array_photo addObject:[model_list.array_img objectAtIndex:1]];
                }
            }
            
            KWNPhotoDetailViewController *detail = [[KWNPhotoDetailViewController alloc] initWithDelegate:self];
            detail.int_tag = 1;
            [self presentViewController:detail animated:YES completion:^{
                
            }];
        }break;
        case KWNQDetailCellTag_imageTwo:{
            UITableViewCell *cell = [self reciveSuperViewCellWithView:button];
            UITableView *tableView = [self reciveSuperViewTableWithView:cell];
            NSIndexPath *index = [tableView indexPathForCell:cell];
            if(tableView.tag == 200){
                Model_questionList *model_list = _array_goodAtData[index.row];
                [_array_photo removeAllObjects];
                [_array_photo addObject:[model_list.array_img objectAtIndex:1]];
                if (model_list.array_img.count == 2) {
                    [_array_photo addObject:[model_list.array_img objectAtIndex:0]];
                }
            }
            else{
                Model_questionList *model_list = _array_AllData[index.row];
                [_array_photo removeAllObjects];
                [_array_photo addObject:[model_list.array_img objectAtIndex:1]];
                if (model_list.array_img.count == 2) {
                    [_array_photo addObject:[model_list.array_img objectAtIndex:0]];
                }
            }
            KWNPhotoDetailViewController *detail = [[KWNPhotoDetailViewController alloc] initWithDelegate:self];
            detail.int_tag = 1;
            [self presentViewController:detail animated:YES completion:^{
                
            }];
            
        }break;
        default:
            break;
    }
}

#pragma mark - 获取上级控件 -
/**
 *  获取上级控件
 */
- (UITableViewCell *)reciveSuperViewCellWithView:(UIView *)view{
    for (UIView *next = [view superview]; next; next = next.superview){
        UIResponder *nextResponder;
        nextResponder = [view superview];
        if(IOS8_VERSION || IOS6_VERSION){
            nextResponder = [view superview];
        }
        else{
            nextResponder = [next nextResponder];
        }
        if ([nextResponder isKindOfClass:[UITableViewCell class]]){
            return (UITableViewCell *)nextResponder;
        }
    }
    return nil;
}

- (UITableView *)reciveSuperViewTableWithView:(UIView *)view{
    for (UIView *next = [view superview]; next; next = next.superview){
        UIResponder *nextResponder;
        if(IOS6_VERSION){
            nextResponder = [view superview];
        }
        else{
            nextResponder = [next nextResponder];
        }
        if ([nextResponder isKindOfClass:[UITableView class]]){
            return (UITableView *)nextResponder;
        }
    }
    return nil;
}


#pragma mark - 点击游览图片 -
/**
 *  点击游览图片
 */
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
    return _array_photo.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
    MWPhoto *photo;
    photo = [MWPhoto photoWithURL:[NSURL URLWithString:_array_photo[index]]];
    return photo;
}

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index{
    switch (_array_photo.count) {
        case 1:{
            [(KWNPhotoDetailViewController *)photoBrowser scrollPageViewToIndex:index andBoolScroll:NO];
        }break;
        case 2:{
            [(KWNPhotoDetailViewController *)photoBrowser scrollPageViewToIndex:index andBoolScroll:YES];
        }break;
        default:
            break;
    } 
}

- (void)tokenIsFailure{
    if(_isAlreadyToken == NO)
    {
        _isAlreadyToken = YES;
        UIAlertView *alter_login;
        if(IOS8_VERSION){
            alter_login = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        }
        else{
            alter_login = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        }
        alter_login.tag = 10003;
        [alter_login show];
    }
}

#pragma mark - 账号被替换下线 -
/**
 *  账号被替换下线
 */
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (alertView.tag) {
        case 10003:{
            _isAlreadyToken = NO;
            KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
            [self pushViewController:login];
        }break;
            
        default:
            break;
    }
}

#pragma mark - 切进程序 -
/**
 *  切进程序
 */
- (void)handleEventWhenAppGoForeground{
    [self getUnReadCount];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [scrollView didScrollViewToScroll];
}


@end
